package hsm.interfacetest;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;

/**
 * 初始化LOG4J
 * 
 * @author LLH
 * @version 1.0.0 2011-9-19 下午02:02:34
 */
public class Log4jInit {

	public static void init() throws IOException {
		FileInputStream fis = null;
		Properties prop = new Properties();
		File f = null;
		try {
			String fileSep = System.getProperty("file.separator");
			String path = System.getProperty("user.dir") + fileSep;
			String fileName = "config" + fileSep + "log4j.properties";
			try {
				fis = new FileInputStream(".." + fileSep + fileName);
			} catch (Exception e) {
				fis = new FileInputStream(fileName);
			}

			prop.load(fis);
			String logfileNameA1 = prop.getProperty("log4j.appender.A1.File");
			prop.put("log4j.appender.A1.File", path + logfileNameA1);
			String logfileNameA2 = prop.getProperty("log4j.appender.A2.File");
			prop.put("log4j.appender.A2.File", path + logfileNameA2);
			String logfileNameA3 = prop.getProperty("log4j.appender.A3.File");
			prop.put("log4j.appender.A3.File", path + logfileNameA3);
			String logfileNameA4 = prop.getProperty("log4j.appender.A4.File");
			prop.put("log4j.appender.A4.File", path + logfileNameA4);

			f = new File(path + logfileNameA1);
			f = new File(f.getParent());
			if (!f.exists()) {
				f.mkdirs();
			}
			PropertyConfigurator.configure(prop);
		} finally {
			if (fis != null)
				fis.close();
		}
	}

}
